package ChainOfResponsibility;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractFruitSorter {
    private int weight;
    protected List<String> fruitBox;
    private AbstractFruitSorter nextFruitSorter;

    public AbstractFruitSorter(int weight)
    {
        this.weight = weight;
        fruitBox = new ArrayList<String>();
    }
    public void setNextFruitSorter(AbstractFruitSorter nextFruitSorter)
    {
        this.nextFruitSorter = nextFruitSorter;
    }

    public void sendFruit(int weight, String fruit)
    {
        if(this.weight <= weight)
        {
            pushBox(fruit);
        }
        else
        {
            if(nextFruitSorter != null)
            {
                nextFruitSorter.sendFruit(weight,fruit);
            }
        }
    }

    protected abstract void pushBox(String fruit);

    public void getFruitBox()
    {
        System.out.println("Weight:" + weight);
        System.out.println("个数:" + fruitBox.size());

        for(String t:fruitBox)
        {
            System.out.print(t + ",");
        }
        System.out.println();
    }

}
